package com.lanhai.fnstore.localstore;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

import com.lanhai.fnstore.Config;
import com.lanhai.fnstore.Tools;

/**
 * 路线锁的缓存
 * @author virus408
 *
 */
public class RoadLocalTools {
	public static void saveFile(List<Integer> list) {
		String filename = String.format("%s\\road\\road.data", Config.localDBRoot );
		RoadTemp tp=new RoadTemp();
		tp.setTmp(list);
		try {
			File ff = new File(filename);
			FileOutputStream fos = new FileOutputStream(ff);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(tp);
			oos.close();
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static List<Integer> loadFile() {
		String filepath = String.format("%s\\road\\", Config.localDBRoot);
		ArrayList<Integer> arr = new ArrayList<Integer>();
		List<String> filelist = Tools.getAllFile(filepath);
		if(filelist==null||filelist.size()==0) return arr;
		
		
		String filename=filelist.get(0); 
			try {
				FileInputStream fileIn = new FileInputStream(filename);
				ObjectInputStream inputReader = new ObjectInputStream(fileIn); 
				RoadTemp tp= (RoadTemp)inputReader.readObject(); 
				inputReader.close(); 
				if(tp.getTmp()!=null&&tp.getTmp().size()>0) {
					arr.addAll(tp.getTmp());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		 
		return arr;
	}
	

}

class RoadTemp {
	private List<Integer> tmp;

	public List<Integer> getTmp() {
		return tmp;
	}

	public void setTmp(List<Integer> tmp) {
		this.tmp = tmp;
	}
	
}